<?php

namespace App\Http\Controllers\user;

use App\Dao\OrdersDao;
use App\Dao\SettingsDao;
use App\Dao\UsersDao;
use App\Exceptions\SysExceptions;
use App\Model\AreaModel;
use App\Services\Cache;
use App\Services\Code;

class OrdersController extends BaseController
{

    //商品下单
    /**
     * @throws SysExceptions
     */
    public function addOrder(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);

        return Code::message('下单成功',200,OrdersDao::addOrder($params));
    }

    public function car_add_order(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        OrdersDao::addCarOrder($params);
        return Code::message('');
    }


    public function get_orders(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        return Code::message('',200,OrdersDao::get_orders($params));
    }

    public function get_user_order_info(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        return Code::message('',200,OrdersDao::get_user_order_info($params));
    }


    public function get_area_shop(): array
    {
        return Code::message('',200,UsersDao::get_shop_builder(request()->all())->get());
    }

    public function areas(){
        if(!Cache::hasCache('area_data')){
            Cache::setCache('area_data',AreaModel::query()->with('child.child')->where('parentid',0)->get());
        }
        return Code::message('',200,Cache::getCacheValue('area_data'));
    }

    /**
     * @throws SysExceptions
     */
    public function hexiao(): array
    {
        $params=  array_merge(request()->all(),[
            'he_user_id'=>getUserToken()
        ]);
        OrdersDao::hexiao($params);
        return Code::message('',200);
    }


    public function get_he_orders(): array
    {
        return Code::message('',200,OrdersDao::get_orders(array_merge([
            'h_user_id'=>getUserToken()
        ],request()->all())));
    }

    public function confirm_order(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        OrdersDao::confirm_order($params);
        return Code::message('',200);
    }

    public function get_now_seven(): array
    {
        return Code::message('',200,SettingsDao::get_seven(getUserToken()));
    }
}
